#include "test_suit.h"

/* all test will be placed here! */

/************************************************ 测试项 ************************************************/

/*************************** DEV测试 ***************************/

/* DEV_MPU9250 测试 */
static void s_test_dev_mpu9250(uint8_t items)
{
    uint16_t    items_bit_flag = 0; 
    dt_3axis_s2 axis_acc       = {0};
    dt_3axis_s2 axis_gyro      = {0};
    dt_3axis_s2 axis_mag       = {0};
    float       temp           = 0;


    if ((items & TEST_MPU9250_ACC) != 0)
    {
        /* 获得MPU9250数据 */
        if (dev_mpu9250_get_data(DEV_MPU9250_DATA_ACC, (void *) &axis_acc) != RET_OK)
        {
            return;
        }

        printf("ACC: x = %d, y = %d, z = %d\r\n", axis_acc.x, axis_acc.y, axis_acc.z);

        /* 标记 */
        items_bit_flag |= TEST_MPU9250_ACC;
    }

    if ((items & TEST_MPU9250_GYRO) != 0)
    {
        /* 获得MPU9250数据 */
        if (dev_mpu9250_get_data(DEV_MPU9250_DATA_GYRO, (void *) &axis_gyro) != RET_OK)
        {
            return;
        }
        
        printf("GYRO: x = %d, y = %d, z = %d\r\n", axis_gyro.x, axis_gyro.y, axis_gyro.z);

        /* 标记 */
        items_bit_flag |= TEST_MPU9250_GYRO;
    }

    if ((items & TEST_MPU9250_MAG) != 0)
    {
        /* 获得MPU9250数据 */
        if (dev_mpu9250_get_data(DEV_MPU9250_DATA_MAG, (void *) &axis_mag) != RET_OK)
        {
            return;
        }
        
        printf("MAG: x = %d, y = %d, z = %d\r\n", axis_mag.x, axis_mag.y, axis_mag.z);

        /* 标记 */
        items_bit_flag |= TEST_MPU9250_MAG;
    }

    if ((items & TEST_MPU9250_TEMP) != 0)
    {
        /* 获得MPU9250数据 */
        if (dev_mpu9250_get_data(DEV_MPU9250_DATA_TEMP, (void *) &temp) != RET_OK)
        {
            return;
        }
        
        printf("temperature = %f\r\n", temp);

        /* 标记 */
        items_bit_flag |= TEST_MPU9250_TEMP;
    }

    if ((items & TEST_MPU9250_YAW) != 0)
    {
        /* MPU9250罗盘测试 */
        if (dev_mpu9250_test_yaw(&temp) != RET_OK)
        {
            return;
        }
        
        printf("yaw = %f\r\n", temp);

        /* 标记 */
        items_bit_flag |= TEST_MPU9250_YAW;
    }

    /* 判断是否有ITEM被执行 */
    if (items_bit_flag == 0)
    {
        printf("TEST_INFO: no test items for dev mpu9250\r\n");
    }

    return;
}

/*************************** APP测试 ***************************/

/* APP_AXIS 测试 */

/* 周期性刷新波形 */
extern void gui_app_axis_update_data(void);

static void s_test_app_axis(uint8_t items)
{
    uint16_t items_bit_flag = 0; 

    if ((items & TEST_APP_AXIS) != 0)
    {
        gui_app_axis_update_data();

        items_bit_flag |= TEST_APP_AXIS;
    }
    /* 判断是否有ITEM被执行 */
    if (items_bit_flag == 0)
    {
        printf("TEST_INFO: no test items for app axis\r\n");
    }

    return;
}

/*********************************************** 调用接口 ***********************************************/
/* 运行选中的测试项 
 * (the parameters must use the emun items defined in data_type.h) 
 * target: 必须唯一, items: 可以测试多个项目
 */
void test_target_run(uint8_t target, uint8_t items)
{
    switch (target)
    {
        case TEST_TARGET_DEV_MPU9250:
        {
            s_test_dev_mpu9250(items);
        } break;

        case TEST_TARGET_APP_AXIS:
        {
            s_test_app_axis(items);
        } break;

        default:break;
    };
}
